$(function () {
    // var loading = weui.loading('loading', {
    //     className: 'custom-classname'
    // });
    var result = Model.represent.getRepresentInfo();
    if (!sessionStorage.getItem('hmdj_stopError')) {
        sessionStorage.setItem('hmdj_stopError', true);
    } else {
        if (result.code) {
            Common.fn.formatOutput(result);
            loading.hide();
            return false;
        }
    }
    // 判断是否有代言
    if ('photo' in result.data) {
        $('.represent-img').attr('src', result.data.photo);
        $('.vendor-level').text('v' + result.data.grade);
        $('.daiyan-money').text(result.data.price);
        $('.daiyan-get').text(result.data.number);
        var nickname = '';
        result.data.nickname.length > 7 ? nickname = result.data.nickname.substr(0, 7) + '...' : nickname = result.data.nickname;
        $('.nickname').text(nickname);
        $('.stop-daiyan').attr('data-id', result.data.businessId);
        if (result.data.notice) {
            weui.alert('代言店铺代言费不足，提醒您取消代言');
        }
        // 终止代言按钮
        $('.stop-daiyan').on('click', function () {
            var id = $(this).attr('data-id');
            weui.confirm('确定要终止代言吗？', {
                title: '系统提示',
                buttons: [{
                    label: '取消',
                    type: 'default',
                    onClick: function () {
                        console.log('no')
                    }
                }, {
                    label: '终止代言',
                    type: 'primary',
                    onClick: function () {
                        var result = Model.represent.cancelRepresent({
                            businessId: id
                        });
                        if (result.code) {
                            alert(result.message);
                            location.reload();
                            return false;
                        }
                        alert(result.data);
                        location.reload();
                    }
                }]
            });
        });
    } else {
        // 没有代言内容
        $('.daiyan-block').addClass('hide');
        $('.daiyan-list').removeClass('hide');
        $('.my-poster').attr('href', 'javascript:weui.alert("代言商品后才能看到海报哦");');
    }
    if(!result.data.income) {
        $('.income').text('0.00');
    }else {
        $('.income').text(result.data.income);
    }
    loading.hide();
});